

#ifndef _UNIX_SOCKET_H_
#define _UNIX_SOCKET_H_

#include "os.h"

typedef int (*unix_socket_cb_packet)(int portfd, int msgid, int pktfd);

typedef struct UnixSocket
{
    int used;
    int listenfd;
    void *userdata;

    int sockfd;

    int client_num;

    unix_socket_cb_packet cb_packet;//一个完整的包到达了
    
    int lua_cb_self;
    char lua_cb_packet[128];

    //读缓冲区
    int buf_read;
    //读缓冲区
    int buf_write;

    //ps. 要放在后面
    struct event ev_read;
    struct event ev_write;
    //ps. 要放在后面
    struct event evt;

}UnixSocket;


int unix_socket_init();
int unix_socket_listen(int fd, const char *path);
int unix_socket_set_cb_packet(int fd, unix_socket_cb_packet cb);

int unix_socket_close(int fd);

void  unix_socket_set_userdata(int fd, void *userdata);
void *unix_socket_get_userdata(int fd);

int unix_socket_is_connectted(int fd);
int unix_socket_get_write_buffd(int fd);
#endif
